package le.grand;

import java.util.ArrayList;
import java.util.List;

public class ReservationInfo {

	private List<ReservationEntry> res = new ArrayList<>();
	private int reservationNumber;

	public ReservationInfo() {
	}

	public List<ReservationEntry> getEntries() {
		return res;
	}

	public int getNumOfChildren() {
		int k = 0;
		for (ReservationEntry re : res) {
			k += re.getNumOfChildren();
		}
		return k;
	}
	
	public List<String> getNames() {
		List<String> names = new ArrayList<>();
		for (ReservationEntry re : res) {
			names.addAll(re.getNames());
		}
		return names;
	}

	public void addNameToLastEntry(String name) {
		ReservationEntry lastEntry = getLastEntry();
		lastEntry.addName(name);
	}

	public int getTotalNumOfPassengers() {
		int k = 0;
		for (ReservationEntry re : res) {
			k += re.getNumOfPassengers();
		}
		return k;
	}
	
	public void setNumOfPassengers(int k) {
		ReservationEntry lastEntry = getLastEntry();
		lastEntry.setNumOfPassengers(k);
	}

	public void addEntry(int numOfPassengers) {
		ReservationEntry re = new ReservationEntry(numOfPassengers);
		this.res.add(re);
	}

	public ReservationEntry getLastEntry() {
		if (res.isEmpty()) {
			res.add(new ReservationEntry());
		}
		return res.get(res.size() - 1);
	}

	public int getNumOfPassengers() {
		int sum = 0;
		for (ReservationEntry re : res) {
			sum += re.getNumOfPassengers();
		}
		return sum;
	}

	public int getReservationNumber() {
		return reservationNumber;
	}

	public void setReservationNumber(int reservationNumber) {
		this.reservationNumber = reservationNumber;
	}

	@Override
	public String toString() {
		return "ReservationInfo [names=" + getNames() + ", reservationNumber=" + reservationNumber
				+ ", numOfPassengers=" + getNumOfPassengers() + "]";
	}

}
